﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Clueless
{
    public partial class JoinHost : Form
    {
        public event EventHandler<JoinEventArgs> AttemptJoin;
        public JoinHost()
        {
            InitializeComponent();
        }

        internal void SetValues(string p1, string p2)
        {
            txtIP.Text = p1;
            txtPort.Text = p2;
        }

        private void btnJoin_Click(object sender, EventArgs e)
        {
            SendJoinMessage(txtIP.Text , txtPort.Text);
            this.Close();
        }

        /// <summary>
        /// Loads the name into the event args and sends it back to the main form
        /// </summary>
        /// <param name="character"></param>
        private void SendJoinMessage(String ip, String port)
        {
            JoinEventArgs args = new JoinEventArgs();
            args.IP = ip;
            args.Port = port;
            OnJoinMessage(args);
        }


        /// <summary>
        /// Call the event trigger
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnJoinMessage(JoinEventArgs e)
        {
            EventHandler<JoinEventArgs> handler = AttemptJoin;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }

    /// <summary>
    /// Event args for a character selection action
    /// </summary>
    public class JoinEventArgs : EventArgs
    {
        public String IP { get; set; }
        public String Port { get; set; }
    }
}
